﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Perovich.GameObjects.Components
{
    public interface IEntityComponentCollection : ICollection<IEntityComponent>
    {
        void Add(IEntityComponent item, bool overwrite);
        T Find<T>() where T : IEntityComponent;
        IEnumerable<T> FindAll<T>() where T : IEntityComponent;
        bool Contains<T>() where T : IEntityComponent;
        bool Remove<T>() where T : IEntityComponent;
        bool RemoveImmediate<T>(bool updateDependencies) where T : IEntityComponent;
        bool RemoveImmediate(IEntityComponent component, bool updateDependencies);
        IEntityComponent this[Type key] { get; }

        event EventHandler<EntityComponentEventArgs> ComponentAdded;
        event EventHandler<EntityComponentRemovedEventArgs> ComponentRemoved;
    }

    public class EntityComponentEventArgs : EventArgs
    {
        IEntityComponent component;

        public EntityComponentEventArgs(IEntityComponent component)
        {
            this.component = component;
        }

        public IEntityComponent Component
        {
            get
            {
                return component;
            }
        }
    }

    public class EntityComponentRemovedEventArgs : EntityComponentEventArgs
    {
        bool updateDependencies;

        public EntityComponentRemovedEventArgs(IEntityComponent component, bool updateDependencies)
            : base(component)
        {
            this.updateDependencies = updateDependencies;
        }

        public bool UpdateDependencies
        {
            get
            {
                return updateDependencies;
            }
        }
    }
}
